package com.may.wlrj.controller;

import java.io.IOException;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.context.request.async.DeferredResult;

import com.may.wlrj.entity.UserEntity;
import com.may.wlrj.entity.UserRoleUnionOrg;
import com.may.wlrj.services.RoleService;
import com.may.wlrj.services.UserService;

@Controller
public class RoleController {
	private RoleService roleService;
    @Autowired
    public void setRoleService(RoleService roleService){
        this.roleService = roleService;
    }
    
    @RequestMapping(value="/getRoleList",method=RequestMethod.GET,produces="text/html;charset=UTF-8;") 
	public @ResponseBody String getRoleList(HttpServletRequest request ,HttpServletResponse response, HttpSession session) throws IOException{	
		return roleService.getRolelist(session);
		
	}
    
    @RequestMapping(value="/getRoles",method=RequestMethod.GET,produces="text/html;charset=UTF-8;") 
	public @ResponseBody String getRoles(HttpServletRequest request ,HttpServletResponse response, HttpSession session) throws IOException{	
		return roleService.getRoles(session);
		
	}
    
    @RequestMapping(value = "/roleaddupdate",method = RequestMethod.POST,produces="text/html;charset=UTF-8;")
    public @ResponseBody DeferredResult<String> roleAddupdate(@RequestBody String objnode,HttpServletRequest request, HttpSession session) throws Exception{
    	DeferredResult<String> deferredResult = new DeferredResult<String>();
    	
        roleService._insertandupdateRole(deferredResult,objnode,request, session);
        return deferredResult;
    }
    
    @RequestMapping(value="/getRoleRights",method=RequestMethod.POST,produces="text/html;charset=UTF-8;") 
	public @ResponseBody String getRoleRights(@RequestBody String objnode,HttpServletRequest request,HttpSession session) throws IOException{

		return roleService.getRoleRights(objnode);
		
	}
    
    @RequestMapping(value = "/roledel",method = RequestMethod.POST,produces="text/html;charset=UTF-8;")
    public @ResponseBody DeferredResult<String> roleDel(@RequestBody String objnode,HttpServletRequest request, HttpSession session) throws Exception{
    	DeferredResult<String> deferredResult = new DeferredResult<String>();
        roleService._RoleDelete(deferredResult,objnode,request, session);
        return deferredResult;
    }
}
